package com.xyebank.cn.controller;

import com.xyebank.cn.commonConstat.SjdConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class HelloController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/hello")
    private String sayHello() {
        return "in consumer call: " + this.restTemplate.getForObject("http://" + SjdConstant.DEMO_SERVICE + "/hello", String.class);
    }


    /**
     * 使用　CLUSTER-IP:PORT　访问
     * @return
     */
    @GetMapping("/hello_clu")
    private String sayHelloByCluster(String cluster) {
        System.out.println("收到的参数：" + cluster);
        if(cluster == null) {
            cluster = "http://10.96.0.215:8766";
        }
        return "in consumer call: " + this.restTemplate.getForObject(cluster + "/hello", String.class);
    }



    /**
     * 使用　CLUSTER-IP:PORT　访问
     * @return
     */
    @GetMapping("/hello_name_clu")
    private String sayHelloByCluName(String service) {
        System.out.println("收到的参数：" + service);
        if(service == null) {
            service = "hello.dev";
        }
        return "in consumer call: " + this.restTemplate.getForObject(service, String.class);
    }


    /**
     * 使用　CLUSTER-IP:PORT　访问
     * @return
     */
    @GetMapping("/hello_ing")
    private String sayHelloByIngress() {
        return "in consumer call: " + this.restTemplate.getForObject("http://com.demo.cn/hello", String.class);
    }
}
